<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="80px"
    >
      <el-form-item label="在用/停用  1：在用；0：停用" prop="isUse">
        <el-input
          v-model="dataForm.isUse"
          placeholder="在用/停用  1：在用；0：停用"
        />
      </el-form-item>
      <el-form-item label="档次名称" prop="name">
        <el-input v-model="dataForm.name" placeholder="档次名称" />
      </el-form-item>
      <el-form-item label="业务补贴比例" prop="subsidyRatio">
        <el-input v-model="dataForm.subsidyRatio" placeholder="业务补贴比例" />
      </el-form-item>
      <el-form-item
        label="业务借调补贴比例 = 补贴比例 * 0.8"
        prop="subsidyRatioSecond"
      >
        <el-input
          v-model="dataForm.subsidyRatioSecond"
          placeholder="业务借调补贴比例 = 补贴比例 * 0.8"
        />
      </el-form-item>
      <el-form-item label="炉工司机补贴比例" prop="carSubsidyRatio">
        <el-input
          v-model="dataForm.carSubsidyRatio"
          placeholder="炉工司机补贴比例"
        />
      </el-form-item>
      <el-form-item
        label="炉工司机借调补贴比例 = 补贴比例 * 0.8"
        prop="carSubsidyRatioSecond"
      >
        <el-input
          v-model="dataForm.carSubsidyRatioSecond"
          placeholder="炉工司机借调补贴比例 = 补贴比例 * 0.8"
        />
      </el-form-item>
      <el-form-item
        label="考核奖标准 考核奖 = 月度考核汇总分数/100 * 考核奖标准"
        prop="assessmentAward"
      >
        <el-input
          v-model="dataForm.assessmentAward"
          placeholder="考核奖标准 考核奖 = 月度考核汇总分数/100 * 考核奖标准"
        />
      </el-form-item>
      <el-form-item
        label="借调考核奖标准 = 考核奖 * 0.8 借调考核奖 = 月度考核汇总分数/100 * 借调考核奖标准"
        prop="assessmentAwardSecond"
      >
        <el-input
          v-model="dataForm.assessmentAwardSecond"
          placeholder="借调考核奖标准 = 考核奖 * 0.8 借调考核奖 = 月度考核汇总分数/100 * 借调考核奖标准"
        />
      </el-form-item>
      <el-form-item label="住房改革补贴" prop="housing">
        <el-input v-model="dataForm.housing" placeholder="住房改革补贴" />
      </el-form-item>
      <el-form-item label="借调住房改革补贴" prop="housingSecond">
        <el-input
          v-model="dataForm.housingSecond"
          placeholder="借调住房改革补贴"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input v-model="dataForm.remarks" placeholder="备注" />
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      dataForm: {
        id: 0,
        isUse: "",
        name: "",
        subsidyRatio: "",
        subsidyRatioSecond: "",
        carSubsidyRatio: "",
        carSubsidyRatioSecond: "",
        assessmentAward: "",
        assessmentAwardSecond: "",
        housing: "",
        housingSecond: "",
        remarks: ""
      },
      dataRule: {
        isUse: [
          {
            required: true,
            message: "在用/停用  1：在用；0：停用不能为空",
            trigger: "blur"
          }
        ],
        name: [
          { required: true, message: "档次名称不能为空", trigger: "blur" }
        ],
        subsidyRatio: [
          { required: true, message: "业务补贴比例不能为空", trigger: "blur" }
        ],
        subsidyRatioSecond: [
          {
            required: true,
            message: "业务借调补贴比例 = 补贴比例 * 0.8不能为空",
            trigger: "blur"
          }
        ],
        carSubsidyRatio: [
          {
            required: true,
            message: "炉工司机补贴比例不能为空",
            trigger: "blur"
          }
        ],
        carSubsidyRatioSecond: [
          {
            required: true,
            message: "炉工司机借调补贴比例 = 补贴比例 * 0.8不能为空",
            trigger: "blur"
          }
        ],
        assessmentAward: [
          {
            required: true,
            message:
              "考核奖标准 考核奖 = 月度考核汇总分数/100 * 考核奖标准不能为空",
            trigger: "blur"
          }
        ],
        assessmentAwardSecond: [
          {
            required: true,
            message:
              "借调考核奖标准 = 考核奖 * 0.8 借调考核奖 = 月度考核汇总分数/100 * 借调考核奖标准不能为空",
            trigger: "blur"
          }
        ],
        housing: [
          { required: true, message: "住房改革补贴不能为空", trigger: "blur" }
        ],
        housingSecond: [
          {
            required: true,
            message: "借调住房改革补贴不能为空",
            trigger: "blur"
          }
        ],
        remarks: [{ required: true, message: "备注不能为空", trigger: "blur" }]
      }
    };
  },
  methods: {
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        if (this.dataForm.id) {
          this.$http({
            url: this.$http.adornUrl(
              `/sys/dutyDegree/info/${this.dataForm.id}`
            ),
            method: "get",
            params: this.$http.adornParams()
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataForm.isUse = data.dutyDegree.isUse;
              this.dataForm.name = data.dutyDegree.name;
              this.dataForm.subsidyRatio = data.dutyDegree.subsidyRatio;
              this.dataForm.subsidyRatioSecond =
                data.dutyDegree.subsidyRatioSecond;
              this.dataForm.carSubsidyRatio = data.dutyDegree.carSubsidyRatio;
              this.dataForm.carSubsidyRatioSecond =
                data.dutyDegree.carSubsidyRatioSecond;
              this.dataForm.assessmentAward = data.dutyDegree.assessmentAward;
              this.dataForm.assessmentAwardSecond =
                data.dutyDegree.assessmentAwardSecond;
              this.dataForm.housing = data.dutyDegree.housing;
              this.dataForm.housingSecond = data.dutyDegree.housingSecond;
              this.dataForm.remarks = data.dutyDegree.remarks;
            }
          });
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(
              `/sys/dutyDegree/${!this.dataForm.id ? "save" : "update"}`
            ),
            method: "post",
            data: this.$http.adornData({
              id: this.dataForm.id || undefined,
              isUse: this.dataForm.isUse,
              name: this.dataForm.name,
              subsidyRatio: this.dataForm.subsidyRatio,
              subsidyRatioSecond: this.dataForm.subsidyRatioSecond,
              carSubsidyRatio: this.dataForm.carSubsidyRatio,
              carSubsidyRatioSecond: this.dataForm.carSubsidyRatioSecond,
              assessmentAward: this.dataForm.assessmentAward,
              assessmentAwardSecond: this.dataForm.assessmentAwardSecond,
              housing: this.dataForm.housing,
              housingSecond: this.dataForm.housingSecond,
              remarks: this.dataForm.remarks
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    }
  }
};
</script>
